<html>
<head><meta charset="utf-8"><title>Guarantee Big Endian of `Ipv4Addr::inner` · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Guarantee.20Big.20Endian.20of.20.60Ipv4Addr.3A.3Ainner.60.html">Guarantee Big Endian of `Ipv4Addr::inner`</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="205766048"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Guarantee%20Big%20Endian%20of%20%60Ipv4Addr%3A%3Ainner%60/near/205766048" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Guarantee.20Big.20Endian.20of.20.60Ipv4Addr.3A.3Ainner.60.html#205766048">(Aug 03 2020 at 07:27)</a>:</h4>
<p>cc <a href="https://github.com/rust-lang/rust/issues/75086">#75086</a><br>
Currently, we documented that it is Big Endian: <a href="https://github.com/rust-lang/rust/blob/7637cbb79bad4fdc29906a21847096a997a13631/library/std/src/net/ip.rs#L383-L386">https://github.com/rust-lang/rust/blob/7637cbb79bad4fdc29906a21847096a997a13631/library/std/src/net/ip.rs#L383-L386</a></p>
<p>But in <a href="https://github.com/rust-lang/rust/issues/75086">#75086</a>, I have to change its constructor to take <code>u32::from_le_bytes</code>, which is Little Endian.<br>
I am confused now. Do we check every assignment to <code>inner</code> as big endian ?</p>



<a name="205767787"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Guarantee%20Big%20Endian%20of%20%60Ipv4Addr%3A%3Ainner%60/near/205767787" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Guarantee.20Big.20Endian.20of.20.60Ipv4Addr.3A.3Ainner.60.html#205767787">(Aug 03 2020 at 07:54)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="124288">@oli</span> we could chat here about <a href="https://github.com/rust-lang/rust/issues/75086">#75086</a></p>



<a name="205769442"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Guarantee%20Big%20Endian%20of%20%60Ipv4Addr%3A%3Ainner%60/near/205769442" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Guarantee.20Big.20Endian.20of.20.60Ipv4Addr.3A.3Ainner.60.html#205769442">(Aug 03 2020 at 08:15)</a>:</h4>
<p>Update, the current code is correct, but I still think the endianness requirement need to be documented on <code>Ip*Addr</code>.</p>



<a name="205825408"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Guarantee%20Big%20Endian%20of%20%60Ipv4Addr%3A%3Ainner%60/near/205825408" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Guarantee.20Big.20Endian.20of.20.60Ipv4Addr.3A.3Ainner.60.html#205825408">(Aug 03 2020 at 17:53)</a>:</h4>
<p>I think that FIXME was wrong (or perhaps just incomplete)</p>



<a name="205825455"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Guarantee%20Big%20Endian%20of%20%60Ipv4Addr%3A%3Ainner%60/near/205825455" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Guarantee.20Big.20Endian.20of.20.60Ipv4Addr.3A.3Ainner.60.html#205825455">(Aug 03 2020 at 17:53)</a>:</h4>
<p>all of those <code>u32::from_[bln]e_bytes</code> constructors result in a native-endian <code>u32</code></p>



<a name="205825549"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Guarantee%20Big%20Endian%20of%20%60Ipv4Addr%3A%3Ainner%60/near/205825549" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Guarantee.20Big.20Endian.20of.20.60Ipv4Addr.3A.3Ainner.60.html#205825549">(Aug 03 2020 at 17:54)</a>:</h4>
<p>you could use that, but it will still need to be wrapped in <code>u32::to_be</code></p>



<a name="205826928"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Guarantee%20Big%20Endian%20of%20%60Ipv4Addr%3A%3Ainner%60/near/205826928" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Guarantee.20Big.20Endian.20of.20.60Ipv4Addr.3A.3Ainner.60.html#205826928">(Aug 03 2020 at 18:05)</a>:</h4>
<p>That certainly is. Oh god I was confused about those endianness. Also the doc for u32 methods should have say directly your point.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>